package com.example.neutonote2.viewmodel;

import android.app.Application;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import java.util.List;

import com.example.neutonote2.data.model.Category;
import com.example.neutonote2.data.repository.CategoryRepository;

/**
 * 分类的ViewModel，用于管理UI相关的分类数据
 */
public class CategoryViewModel extends AndroidViewModel {
    private final CategoryRepository repository;
    private final LiveData<List<Category>> allCategories;
    private final LiveData<List<Category>> defaultCategories;

    public CategoryViewModel(Application application) {
        super(application);
        repository = new CategoryRepository(application);
        allCategories = repository.getAllCategories();
        defaultCategories = repository.getDefaultCategories();
    }

    // 获取所有分类
    public LiveData<List<Category>> getAllCategories() {
        return allCategories;
    }
    
    // 获取默认分类
    public LiveData<List<Category>> getDefaultCategories() {
        return defaultCategories;
    }

    // 按ID获取分类
    public LiveData<Category> getCategoryById(int id) {
        return repository.getCategoryById(id);
    }
    
    // 按名称获取分类
    public LiveData<Category> getCategoryByName(String name) {
        return repository.getCategoryByName(name);
    }

    // 插入分类
    public void insert(Category category) {
        repository.insert(category);
    }

    // 更新分类
    public void update(Category category) {
        repository.update(category);
    }

    // 删除分类
    public void delete(Category category) {
        repository.delete(category);
    }
} 